function AfterSearch(data) {
  //data = Process("scripts.utils.AfterSearchForTimeProcess", data);

  for (var i in data.data) {
    if (data.data[i].owner && data.data[i].owner.length) {
      data.data[i].owner = data.data[i].owner.join("，");
    }
  }
  return data;
}


function InitSelect(param) {
    // console.log("param--->",param)
    var query = new Query();
    var wheres = [{ ":deleted_at": "删除", "=": null }]
    if(param.parent_id){
      wheres.push({ ":parent_id": "父级ID", "=": param.parent_id })
    }
    var res = query.Get({
      wheres: wheres,
      select: ["id as value", "name as label"],
      from: "business",
    });
    // console.log("res---->",res);
    const newres = [{label:"N/A",value:"0"}, ...res];
   
    return newres;
  }

  function BusiSelect(param) {
    //console.log("param--->",param)
    var query = new Query();
    var wheres = [{ ":deleted_at": "删除", "=": null }]
    if(param.parent_id){
      wheres.push({ ":parent_id": "父级ID", "=": 4 })
    }
    var res = query.Get({
      wheres: wheres,
      select: ["name as value", "name as label"],
      from: "business",
    });
    console.log("res--BusiSelect-->",res);
   
    return res;
  }

  /**
 * 传参演示
 */
function Args(...args) {
  console.log(args);
  const user_id1 = Process("session.Get", "user_id");
  console.log("user_id1",user_id1)
  console.log("---END1---")
  return args;
}

function Find(payload) {
  //console.log("---START--1---")
 // console.log(payload);
  var res = Process("models.cmdb.business.find", payload, {});
  //const user_id1 = Process("session.Get", "user_id");
  //console.log("user_id1",user_id1)
  //console.log("---END--1---")
  return [res];
}

function Save(payload) {
  console.log("payload-->",payload);
  var res = Process("models.cmdb.business.save", payload);
  console.log("res-->",res);
  return [res];
}

  function test() {
    var busi = Process("models.cmdb.business.get", {
      withs: {
        parent: {
          query: {
            select: ["name", "id"],
          },
        },
      },
      wheres: [{ column: "parent_id", value: 4, op: "=" }],
      orders: [{ column: "id", option: "desc" }],
      limit: 1,
    });
    return busi;
  }

  
  /**
   * 在关联处理器 save 之后运行
   * @param result 处理器运行结果
   */
  function AfterSave(result) {
    return result;
  }
  
  /**
   * 在关联处理器 create 之后运行
   * @param result 处理器运行结果
   */
  function AfterCreate(result) {
    return result;
  }
  
  /**
   * 在关联处理器 update 之后运行
   * @param result 处理器运行结果
   */
  function AfterUpdate(result) {
    return result;
  }
  
  /**
   * 在关联处理器 delete 之后运行
   * @param result 处理器运行结果
   */
  function AfterDelete(result) {
    return result;
  }
  

  function Search(...args) {
    console.log("args",args);
    let param = {
      wheres: [
        { column: "name", op: "like",value: "%BI%" }
      ]
    }
    const target = Object.assign({}, args[0], param);
    var res = Process("models.cmdb.business.Paginate", target,args[1],args[2]);
   

    return res;
  }
      
  
